//
//  ST_DefaultFilterOfVideo.swift
//  BTVideo
//
//  Created by DouLei on 2019/10/17.
//  Copyright © 2019 DouLei. All rights reserved.
//

import UIKit
import RealmSwift

/**
 用来保存筛选
 */
class ST_DefaultFilterOfVideo: Object {
    
    @objc dynamic var sex: ST_FilterOptionSelectModel?
    
    @objc dynamic var age: ST_FilterOptionRangeModel?
    
    @objc dynamic var direction: ST_FilterOptionRangeModel?
    
    @objc dynamic var ST_Zodiac: ST_FilterOptionSelectModel?
    
    @objc dynamic var ideal: ST_FilterOptionSelectModel?
    
    @objc dynamic var stature: ST_FilterOptionSelectModel?
    
    @objc dynamic var sexualOrientation: ST_FilterOptionSelectModel?
    //保存重置数据
    @objc dynamic var isResetData = true
}

protocol ST_DetachableObject: AnyObject {
  func detached() -> Self
}

extension Object: ST_DetachableObject {
  func detached() -> Self {
    let detached = type(of: self).init()
    for property in objectSchema.properties {
      guard let value = value(forKey: property.name) else {
        continue
      }
      if let detachable = value as? ST_DetachableObject {
        detached.setValue(detachable.detached(), forKey: property.name)
      } else { // Then it is a primitive
        detached.setValue(value, forKey: property.name)
      }
    }
    return detached
  }
}

class ST_FilterOptionRangeModel:Object {
    
    /**
     update key
     */
    @objc dynamic var optionKey = ""
    
    @objc dynamic var title = ""
    
//    两个值使用 minValue ... maxValue
    @objc dynamic var minValue = 0
    @objc dynamic var maxValue = 0
    
//    一个值使用
    @objc dynamic var slideValue = 0
    
    /**
     一个值 string 使用
     */
    @objc dynamic var slideStringValue = ""
}

class ST_FilterOptionSelectModel:Object {
    
    @objc dynamic var selectedId:String?
    @objc dynamic var selectedText:String?
    @objc dynamic var optionKey = ""
    @objc dynamic var title = ""
    
}
